		var items;
		var citys;
		var page=1;
		var totalPage;
		var pageSize=10;
		var endPage=10;
		var totalSize;
		var startPage=1;
		var selectCarrier="";
		var carrierArry=new Array();
		var map = {};
		
		Array.prototype.delRepeat=function(){  
			     var newArray=[];  
			     var provisionalTable = {};  
			     for (var i = 0, item; (item= this[i]) != null; i++) {  
			         if (!provisionalTable[item]) {  
			             newArray.push(item);  
			             provisionalTable[item] = true;  
			         }  
			     }  
			     return newArray;  
			 }; 

		$(function() {
		 $("#searchFlight").click(function() { //按钮单击事件

			var flightDate=$("#datepicker").val();
			getQuery(flightDate);
			}); 
	});

function getQuery(flightDate){
	var flightName= $("#flightName").val();
	var	arriName=$("#arriName").val();
	var flightCode= $("#flightCode").val();
	var	arriCode=$("#arriCode").val();
	var result=checkSearch(flightName,flightCode,arriName,arriCode,flightDate);
	if(result){
		initSearch(flightCode,arriCode,flightDate);
	}else{
		alert('请选择查询条件');
	}
}
function checkSearch(flightName,flightCode,arriName,arriCode,flightDate){
	if(flightName!=null&&arriName!=null&&flightDate!=null&&flightName!=''&&arriName!=''&&flightDate!=''){
		$("#flightName").val(flightName);
		$("#flightCode").val(flightCode);
		$("#arriName").val(arriName);
		$("#arriCode").val(arriCode);
		$("#datepicker").val(flightDate);
		
		$("#showFlightName").text(flightName);
		$("#showArriName").text(arriName);
		$("#showFlightDate").text(flightDate);
		
		var day=getDayOfWeek(flightDate);

		$("#xqj").text(day);
		
		return true;
	}
	return false;
}
	function nextDay(){  
		var flightDate=$("#datepicker").val();
		
		if(flightDate!=null&&flightDate!=''){
		flightDate = flightDate.replace('-', '/');
	      
	      var t1 = new Date(new Date(flightDate).valueOf() + 1*24*60*60*1000);// 日期加上指定的天数
	     
	      flightDate=t1.getFullYear() + "-" + (t1.getMonth() + 1) + "-" + t1.getDate();
	      
	      getQuery(flightDate);
	  
		}else{
			alert('请选择查询条件');
		}
	}  
	
	function oneDay(){    
		var flightDate=$("#datepicker").val();
		
		if(flightDate!=null&&flightDate!=''){
		flightDate = flightDate.replace('-', '/');
	      
	      var t1 = new Date(new Date(flightDate).valueOf()- 1*24*60*60*1000);// 日期加上指定的天数
	     
	      flightDate=t1.getFullYear() + "-" + (t1.getMonth() + 1) + "-" + t1.getDate();
	      
	      getQuery(flightDate);
	   
		}else{
			alert('请选择查询条件');
		}	
	} 
	
	
	function getDayOfWeek(dayValue){    
	    var day = new Date(Date.parse(dayValue.replace(/-/g, '/')));                             //将日期值格式化    
	    var today = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");  //创建星期数组   
	    return today[day.getDay()];                                                           //返一个星期中的某一天，其中0为星期日    
	}    

function getQueryString(name) {   
	var url=decodeURI(window.location.search);
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = url.substr(1).match(reg);   
		if (r != null) 
		return unescape(r[2]);
	return null;   
	}

		function initSearch(flightCode,arriCode,flightDate){
			//打开文件，并通过回调函数处理获取的数据
			d = new Date(); // 创建 Date 对象。 
			s="temp";
			s += d.getYear() ; // 获取年份。 
			s += d.getMonth()+1 ; // 获取月份。 
			s += d.getDate(); // 获取日。 
			s += d.getHours(); // 获取小时。
			s += d.getMinutes(); // 获取分钟。
			s += d.getSeconds(); // 获取秒数。
			$('.both').remove();
			var url=encodeURI(__ctxPath+"/front/order/orderSearch.do?cmd=getApointName&flightCode="+flightCode+"&arriCode="+arriCode+"&tempVar="+s);
			$.ajax({
			type : "post",
			url : url,
			dataType : "String",
			contentType: "charset=UTF-8", 
			async:false,
			success : function(data) {
				citys=eval(data);
			},
			error : function() {
				alert('获取城市名称失败!');
			}
		});
			var ibeUri=encodeURI(__ctxPath+ "/front/order/orderSearch.do?cmd=searchOrder&flightCode="+flightCode+"&arriCode="+arriCode+"&flightDate="+flightDate+"&tempVar="+s);
		$.ajax({
				type : "post",
				url :ibeUri,
				dataType : "json",
//				dataType : "string",
				contentType: "application/x-www-form-urlencoded; charset=utf-8", 
				success : function(data) {
					alert(data);
					items=data.childNodes;
					alert(items.length);
					$("#total").text(items.length);
					//test
//					items=eval(test).childNodes;
					selectCarrier="";
					initPage(true,items.length);
					//去重航空公司二字码
					 for(var i=0;i<items.length;i++){
							var carrier=items[i].childNodes[22].childNodes;
							carrierArry.push(carrier);
							}
					 carrierArry=carrierArry.delRepeat();
					 
					 //过滤后的航空公司对应航班
					 for ( var int = 0; int < carrierArry.length; int++) {
						 var carrierMapValue=new Array();
						 for(var j=0;j<items.length;j++){
								var carrierValue=items[j];
								if(carrierValue.childNodes[22].childNodes.toString()==carrierArry[int].toString()){
								carrierMapValue.push(carrierValue);
								}
							}
						 map[carrierArry[int]]=carrierMapValue;
					}
					
					$("#fligtCode tr").remove(); 

					var tr_str="<tr>";   
	                tr_str+="<td width='16%'>仅显示：<a href='javascript:filterCarrier("+'""'+")'><font color='#FF0000'>全部</font></a></td>";   
	                for ( var int = 0; int < carrierArry.length; int++) {
	                	var carrier="'"+carrierArry[int]+"'";
	                	var carrierName=carrierArry[int];
	                	for(var i=0;i<airLines.length;i++){
	                		if(carrierArry[int]==airLines[i].code){
	                			carrierName=airLines[i].airName;
	                			break;
	                		}
	                	}
//	                	tr_str+="<td width='12%'><a href='javascript:filterCarrier("+'"carrierArry[int]"'+")'>"+carrierArry[int]+"</a></td>";   
	                	tr_str+='<td width="12%"><a href="javascript:void(0)" onclick="javascript:filterCarrier('+carrier+')">'+carrierName+'</a></td>';   
			         }
	                tr_str+="</tr>";
	                $("#fligtCode").append(tr_str); 
					
				},
				error : function() {
					alert('失败!');
				}
			});
	}
	
	//下一页
	function next(){
		if(page+1>totalPage)		
		 {
			alert('已经是最后一页');
			return;
		}
		page=page+1;
		initPage(false, totalSize);
	}
	
	//上一页
	function pre(){
		if(page-1<1)		
		 {
			alert('已经是第一页');
			return;
		}
		page=parseInt(page)-1;
		initPage(false, totalSize);
	}
	//页面跳转
	function goPage(page){
		this.page=page;
		initPage(false, totalSize);
	}
	//过滤航空公司
	function filterCarrier(selectCarrier){
		this.selectCarrier=selectCarrier;
		var selectItem=items;
		if(selectCarrier!=""){
			this.selectCarrier=selectCarrier;
			selectItem=map[selectCarrier];
		}
		initPage(true,selectItem.length);
	}
	//初始化分页数据
	function initPage(firstInit,totalSize){
		 if(firstInit==true){
				page=1;
				this.totalSize=totalSize;
				totalPage=Math.ceil(totalSize/pageSize);
		 }
		 startPage=(page-1)*10;
		 endPage=page*10;
		 if(selectCarrier!=""){
				 createHtml(map[selectCarrier]);
			}else{
				 createHtml(items);
			}
	}
	//创建航班数据
	function createHtml(selectItem){
		$('.both').remove();
		var html="<div class='both'> ";
		 for(startPage;startPage<endPage;startPage++){
			 if(startPage<totalSize){
//				 alert(selectItem[currentPage].childNodes[22].childNodes);
			var carrier=selectItem[startPage].childNodes[22].childNodes;
			var flight=selectItem[startPage].childNodes[12].childNodes;
			var duptDate=selectItem[startPage].childNodes[14].childNodes;
			var arrivalDate=selectItem[startPage].childNodes[4].childNodes;
			var duptTime=selectItem[startPage].childNodes[6].childNodes;
			var ariTime=selectItem[startPage].childNodes[13].childNodes;
			var boardPoint=selectItem[startPage].childNodes[8].childNodes;
			var offPoint=selectItem[startPage].childNodes[7].childNodes;
			var flightTime=selectItem[startPage].childNodes[16].childNodes;
			var tpm=selectItem[startPage].childNodes[11].childNodes;
			var stop=selectItem[startPage].childNodes[24].childNodes;

			var boardPointName=selectItem[startPage].childNodes[8].childNodes;
			var offPointName=selectItem[startPage].childNodes[7].childNodes;
			for(var city in citys){
				if(boardPointName==citys[city].name){
					boardPointName=citys[city].value;
						break;
				}
			}	
			for(var city in citys){
				if(offPointName==citys[city].name){
					offPointName=citys[city].value;
					break;
				} 
			}
			var yPrice=selectItem[startPage].childNodes[17].childNodes;
			var airportTax=selectItem[startPage].childNodes[0].childNodes;

			
			var carrierName='';
        	for(var i=0;i<airLines.length;i++){
        		if(carrier==airLines[i].code){
        			carrierName=airLines[i].name;
        			break;
        		}
        	}
			//if(carrier=='CZ'){
			html+="<div id=\"content\">"
          	+"<div id=\"list\">"
          	+"<div class=\"t0\"><img src="+__ctxPath+"/resource/front/image/newpic/CZ.gif /></div>"
          	+"<div class=\"t1\">"+carrierName+"<br /><span>"+carrier+flight+"</span></div>"
          	+"<div class=\"t2\">"+duptTime+"<br /><span>"+ariTime+"</span></div>"
          	+" <div class=\"t3\">"+boardPointName+"<br /><span>"+offPointName+"	</span></div>"
          	+"<div class=\"t4\">"+yPrice+"<span>/Y舱</span></div>"
          	+" <div class=\"t5\" >"
          	+"<a href=\"#\"title=\"更改条件:需每次收取票面价10%的改签费<br>退票条件:需收取票面价20%的退票费<br>签转条件:不允许签转\">退改签</a>"
          	+"</div>"
          	+"<div class=\"t6\">￥50/￥180</div>  "
          	+"<div class=\"t7\"><a href="+__ctxPath+"/front/order/orderSearch.do?cmd=bookin&" +
          			"flight="+flight+"&carrier="+carrier+"&cabin=M&departure_day="+duptDate+"&duptTime="+duptTime+"&ariTime="+ariTime+"" +
          					"&tmp="+tpm+"&flyTime="+flightTime+"&boardPointName="+boardPointName+"&offPointName="+offPointName+"&price="+yPrice+
          							"&yPrice="+yPrice+"&departure_city="+boardPoint+"&arrival_city="+offPoint+"&stop="+stop+"&airportTax="+airportTax+"&fuelSurTax="+180+"></a></div> "
          	+"</div>"
			+"<a class=\"button\" onclick=\"senfe(this);\">展开舱位>></a>";
          		var classes=selectItem[startPage].childNodes[1].childNodes;
        		var innerHtml="";
				if (typeof(classes) != "undefined") { 
		
				for ( var index = 0; index < classes.length; index++) {
					var obj=classes[index].childNodes;
					var policyId=obj[2].childNodes;
					var price=obj[1].childNodes;
					var cabin=obj[6].childNodes;
					var discount=obj[8].childNodes;
					innerHtml+="<div id=\"list\">"
	          	+" <div class=\"t0\"></div>"
	          	+" <div class=\"t1\"></div>"
	          	+" <div class=\"t2\"></div>"
	          	+"<div class=\"t3\"></div>"
	          	+"<div class=\"t4\">￥"+price+"<span>/"+cabin+"舱</span></div>"
	          	+" <div class=\"t5\" ><a href=\"#\"title=\"更改条件:需每次收取票面价10%的改签费<br>退票条件:需收取票面价20%的退票费<br>签转条件:不允许签转\">退改签</a></div>"
	          	+"<div class=\"t6\">￥"+airportTax+"/￥"+180+"</div>"
	          	+" <div class=\"t7\"><a href="+__ctxPath+"/front/order/orderSearch.do?cmd=bookin&" +
	          			"policyId="+policyId+"&discount="+discount+"&flight="+flight+"&carrier="+carrier+"&cabin="+cabin+"&departure_day="+duptDate+"&duptTime="+duptTime+"&ariTime="+ariTime+"" +
      					"&tmp="+tpm+"&flyTime="+flightTime+"&boardPointName="+boardPointName+"&offPointName="+offPointName+"&price="+price+
      					"&yPrice="+yPrice+"&departure_city="+boardPoint+"&arrival_city="+offPoint+"&stop="+stop+"&airportTax="+airportTax+"&fuelSurTax="+180+"></a></div> "
	          	+"</div>";
				}	
			}
          	
			html+=innerHtml+"<div id=\"end\">里程"+tpm+"公里 | 历时："+flightTime+"小时 | 经停："+stop+"</div></div>";
        	 }else{
				 break;
			 }
		}
		//	}
		//});
		  html+="</div> ";
		 $('.flightlist').after(html);
		 var pageShow="";
		 for ( var int = 1; int <= totalPage; int++) {
			 pageShow+="<a href='javascript:goPage("+int+")'>"+int+"</a>&nbsp;";
		}
		 var pageContent='&lt;<a href="javascript:void(0)" onclick="pre()">上一页</a>&gt;'+pageShow+' &lt;<a href="javascript:void(0)" onclick="next()">下一页</a>&gt;';
		 $('.flight_page').empty();
		 $('.flight_page').append(pageContent);
		 
	}